package view.backend.customer;

import java.awt.Font;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import view.generaldesign.DesignLayout;

/**
 *
 * @author Sonny Sandberg
 */
public class AdminCustomerName
{
    private JPanel adminCustomerPanel;
    private JTextField tFieldName;
    private JCheckBox cBox;
    private AdminCustomer adminCustomer;

    public AdminCustomerName(AdminCustomer view)
    {
        adminCustomer = view;
        
        adminCustomerPanel = new JPanel(null);
        adminCustomerPanel.setBounds(0, 0, 300, 105);
        adminCustomerPanel.setBorder(BorderFactory.createTitledBorder(DesignLayout.T_FIELD_RED, "Kunde Info", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, DesignLayout.STANDARD));
        adminCustomerPanel.setOpaque(false);
        
        JLabel lblName = new JLabel("Navn");
        lblName.setBounds(10, 25, 150, 18);
        lblName.setFont(DesignLayout.STANDARD.deriveFont(Font.BOLD));
        
        JLabel lblMortician = new JLabel("Bedemand?");
        lblMortician.setBounds(30, 75, 100, 18);
        lblMortician.setFont(DesignLayout.STANDARD);
        
        tFieldName = new JTextField();
        tFieldName.setBounds(10, 45, 250, 25);
        tFieldName.setBorder(DesignLayout.T_FIELD_RED);
        tFieldName.setBackground(DesignLayout.T_FIELD_BG_COLOR);
        tFieldName.setFont(DesignLayout.STANDARD);
        tFieldName.addKeyListener(new KeyAdapter() 
        {
            @Override
            public void keyReleased(KeyEvent e)
            {
                adminCustomer.getCustomerModel().setName(tFieldName.getText());
                adminCustomer.updateNewCustomerPanel();
            }
        });
        
        cBox = new JCheckBox();
        cBox.setBounds(10, 73, 20, 20);
        cBox.setOpaque(false);
        cBox.addItemListener(new ItemListener() 
        {
            @Override
            public void itemStateChanged(ItemEvent e)
            {
                adminCustomer.getCustomerModel().setMortician(cBox.isSelected());
                adminCustomer.updateNewCustomerPanel();
            }
        });
        
        adminCustomerPanel.add(lblName);
        adminCustomerPanel.add(lblMortician);
        adminCustomerPanel.add(tFieldName);
        adminCustomerPanel.add(cBox);
        
        adminCustomerPanel.setVisible(true);
    }
    
    public void setFieldsFromModel()
    {
        tFieldName.setText(adminCustomer.getCustomerModel().getName());
        cBox.setSelected(adminCustomer.getCustomerModel().isMortician());
    }

    public JPanel getPanel()
    {
        return adminCustomerPanel;
    }
}